<template>
    <view class="app">
        <load :ready="ready"></load>
		
		<view class="swiper">
			<u-swiper :list="list" height="500" border-radius='0'></u-swiper>
		</view>
		<view class="wrap">
			<view class="desc">
				<view class="title">2米金属包覆软管（一螺一插)</view>
				<view class="prices">
					<text class="price">￥50.00</text>
					元瓶
				</view>
			</view>
			<view class="titlebox">
				<image src="/static/icon_box.png" mode="widthFix" class="icon"></image>
				<text>商品详情</text>
			</view>
			<u-parse :html="content"></u-parse>
		</view>
	</view>
</template>

<script>
import { mapState, mapActions, mapMutations, mapGetters } from 'vuex';
import { mixinsBase } from '@/common/js/mixins';
let that;
export default {
    mixins: [mixinsBase],
    components: {},
    data() {
        return {
            ready: true,
			showDelivery:false,
			showPrices:false,
			showSend:false,
			navlist:[{
				name:'销售属性',
			},{
				name:'商品信息',
			}],
			current: 0,
			tab:0,
			btnStyle: {
				...this.$config.btnStyle,
				width:'100%'
			},
			logValue:'顺丰',
			logistics:[
				{
					name: '顺丰',
					value:1,
				},
				{
					name: '申通',
					value:2,
				},
				{
					name: '韵达',
					value:3,
				},
			],
			showRelevance:false,
			relevanceList:[],
			form:{},
			showStock:false,
			showNot:false,
			id:null,
			info: {
				goods:{},
			},
			attrIndex:0,
			attrInfo:{},
			releData:{},
			list: [{
					image: '/static/pj1.png',
				},
			],
			content: ``,
        };
    },
    onLoad(o) {
		if(o.id){
			this.id = o.id
		}
        that = this;
		// this.getSellList();
		// this.getInit();
    },
    onReady() {
    },
    onShow() {
        // #ifdef H5
        this.$common.h5SetTitle('');
        // #endif
    },
    onUnload() {
        that = null;
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        // this.getInit(data=>{
        //      uni.stopPullDownRefresh();
        //      common.showTip('刷新成功');
        // });
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {},

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {
        //       return {
        // 	// path,
        // 	imageUrl:config.shareImg,
        // 	// title
        // }
    },
    methods: {
		async handleState(){
			uni.showLoading()
			const res = await this.$api.goodsStatus({
				goodsId: this.id,
				status: this.info.goods.status ? 0 : 1
			 });
			 uni.hideLoading();
			 if (res.data.code == this.$config.RESOK) {
				 if(this.info.goods.status == 1){
					  this.$common.showTip('上架成功', 'success');
				 } else{
					  this.$common.showTip('下架成功', 'success');
				 }
				 this.$set(this.info.goods, 'status', this.info.goods.status ? 0 : 1);
			 } else{
				this.$message.error(res.data.msg);
			 }
		},
		async submit() {
			if(this.isLoading) return;
			this.isLoading = true;
			uni.showLoading()
			let info = JSON.parse(JSON.stringify(this.info));
			info.goods.isRecommend = info.goods.isRecommend ? 1 : 0;
			info.goods.isHot = info.goods.isHot ? 1 : 0;
			const res = await this.$api.goodsEdit(info)
			this.isLoading = false;
			uni.hideLoading()
			if (res.data.code == this.$config.RESOK) {
				this.$common.showTip('保存成功', 'success')
			} else {
				this.$message.error(res.data.msg);
			}
		},
		async getSellList(){
			let res = await this.$api.sellList({
				// agencyId:this.userInfo.id
			});
			if (res.data.code == this.$config.RESOK) {
				let list = res.data.rows || [];
				list.forEach(item=>{
					item.label = item.sellName
					item.value = item.id
				})
				
				console.log('list',list);
				this.relevanceList = list
			} 
		},
		async getInit(){
			let relevanceList = [];
			let resSell = await this.$api.sellList({
				// agencyId:this.userInfo.id
			});
			if (resSell.data.code == this.$config.RESOK) {
				relevanceList = resSell.data.rows || [];
			} 
			
			let res = await this.$api.goodsDetail({
				id:this.id
			});
			if (res.data.code == this.$config.RESOK) {
				let info = res.data.data;
				info.goods.isRecommend = info.goods.isRecommend ? true : false;
				info.goods.isHot = info.goods.isHot ? true : false;
				
				if(relevanceList.length){
					relevanceList.forEach(item=>{
						item.label = item.sellName
						item.value = item.id
						if(item.id == info.goods.sellId){
							this.releData = {
								label: item.label,
								value: item.value,
							}
						}
					})
					this.relevanceList = relevanceList
				}
				
				this.info = info
				this.ready=true
			} else {
				this.$message.error(res.data.msg);
			}
		},
		async submitStock(){
			uni.showLoading()
			this.$set(this.info.goodsProductList,this.attrIndex, this.attrInfo)
			let info = JSON.parse(JSON.stringify(this.info));
			info.goods.isRecommend = info.goods.isRecommend ? 1 : 0;
			info.goods.isHot = info.goods.isHot ? 1 : 0;
			const res = await this.$api.goodsEdit(info)
			uni.hideLoading();
			if (res.data.code == this.$config.RESOK) {
				this.showStock = false;
				this.$common.showTip(res.data.msg, 'success')
			} else {
				this.$message.error(res.data.msg);
			}
		},
		async submitPrices(){
			uni.showLoading()
			this.$set(this.info.goodsProductList, this.attrIndex, this.attrInfo)
			let info = JSON.parse(JSON.stringify(this.info));
			info.goods.isRecommend = info.goods.isRecommend ? 1 : 0;
			info.goods.isHot = info.goods.isHot ? 1 : 0;
			const res = await this.$api.goodsEdit(info)
			uni.hideLoading();
			if (res.data.code == this.$config.RESOK) {
				this.showPrices = false;
				this.$common.showTip(res.data.msg, 'success')
			} else {
				this.$message.error(res.data.msg);
			}
		},
		handlePrices(item, index){
			this.attrInfo = {
				...item
			}
			this.attrIndex = index;
			this.showPrices = true
		},
		handleStock(item, index){
			this.attrInfo = {
				...item
			};
			this.attrIndex = index;
			this.showStock = true
		},
		confirmRele(e){
			console.log('confirmRele');
			console.log(e);
			this.releData = e[0];
			this.$set(this.info.goods, 'sellId', e[0].value);
		},
		radioGroupChange(){
			
		},
		radioChange(){
			
		},
		handleTab(e){
			this.tab = e;
		},
		change(e){
			this.current = e;
		},
        ...mapActions([])
    },
    computed: {
        ...mapState({
            userInfo: 'userInfo'
        })
    }
};
</script>

<style scoped lang="scss">
.wrap{
	z-index: 9;
	overflow: hidden;
	.desc{
		padding: 20rpx 30rpx;
		border-bottom: 1px solid #ddd;
		.title{
			font-size: 18px;
			font-weight: bold;
			margin-bottom: 6px;
		}
	}
	.prices{
		font-size: 14px;
		.price{
			font-size: 16px;
		}
	}
}
.titlebox{
	display: flex;
	padding: 16rpx 30rpx;
	align-items: center;
	.icon{
		width: 18px;
		height: 18px;
	}
	text{
		margin-left: 5px;
		font-size: 16px;
	}
}

// <view class="wrap">
// 			<view class="desc">
// 				<view class="title">2米金属包覆软管（一螺一插)</view>
// 			
// 			</view>
// 			<view class="titlebox">
// 				<image src="/static/icon_box.png" mode="widthFix" class="icon"></image>
// 				<text>商品详情</text>
// 			</view>
// 			<u-parse :html="info.goods.detail"></u-parse>
// 		</view>
.order-foot{
	padding: 10rpx 30rpx;
	width: 100%;
	position: fixed;
	left: 0;
	bottom: 0;
	z-index: 99;
	 background-color: #F8FAFD;
	 display: flex;
	 justify-content: space-between;
	 .btn-item{
		 width: 48%;
	 }
}
</style>
